package com.github.lzyzsd.circleprogress.demo;

import com.github.lzyzsd.circleprogress.ArcProgress;
import com.github.lzyzsd.circleprogress.CircleProgress;
import com.github.lzyzsd.circleprogress.DonutProgress;
import com.github.lzyzsd.circleprogress.Utils;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;

public class SlideAbility extends Ability {
    private PageSlider pageSlider;
    private Component[] components;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_layout_slide);

        ComponentContainer.LayoutConfig config
                = new ComponentContainer.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT,ComponentContainer.LayoutConfig.MATCH_PARENT);

        //layout one
        DependentLayout layout1 = new DependentLayout(this);
        layout1.setLayoutConfig(config);
        ArcProgress arcProgress = new ArcProgress(this);
        DependentLayout.LayoutConfig dependentLayoutConfig = new DependentLayout.LayoutConfig(Utils.dp2px(getResourceManager(),200),Utils.dp2px(getResourceManager(),200));
        dependentLayoutConfig.addRule(DependentLayout.LayoutConfig.CENTER_IN_PARENT);
        arcProgress.setLayoutConfig(dependentLayoutConfig);
        layout1.addComponent(arcProgress);

        //layout two
        DependentLayout layout2 = new DependentLayout(this);
        layout2.setLayoutConfig(config);
        DonutProgress donutProgress = new DonutProgress(this);
        DependentLayout.LayoutConfig dependentLayoutConfig2 = new DependentLayout.LayoutConfig(Utils.dp2px(getResourceManager(),200),Utils.dp2px(getResourceManager(),200));
        dependentLayoutConfig2.addRule(DependentLayout.LayoutConfig.CENTER_IN_PARENT);
        donutProgress.setLayoutConfig(dependentLayoutConfig2);
        layout2.addComponent(donutProgress);

        //layout three
        DependentLayout layout3 = new DependentLayout(this);
        layout3.setLayoutConfig(config);
        CircleProgress circleProgress = new CircleProgress(this);
        DependentLayout.LayoutConfig dependentLayoutConfig3 = new DependentLayout.LayoutConfig(Utils.dp2px(getResourceManager(),200),Utils.dp2px(getResourceManager(),200));
        dependentLayoutConfig3.addRule(DependentLayout.LayoutConfig.CENTER_IN_PARENT);
        circleProgress.setLayoutConfig(dependentLayoutConfig3);
        layout3.addComponent(circleProgress);

        components = new Component[]{layout1,layout2,layout3};
        pageSlider = (PageSlider)findComponentById(ResourceTable.Id_page_slider);
        pageSlider.setProvider(new PageSliderProvider() {
            @Override
            public int getCount() {
                return components.length;
            }
            @Override
            public Object createPageInContainer(ComponentContainer componentContainer, int i) {
                componentContainer.addComponent(components[i]);
                return null;
            }
            @Override
            public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
                componentContainer.removeComponent((Component)o);
            }
            @Override
            public boolean isPageMatchToObject(Component component, Object o) {
                return component == o;
            }
        });

    }
}
